let isCollapse, topicAll = []
const vm = new Vue({
	el: '#userList',
	data() {
		return {
			visible: false,
			isCollapse: false,
			height: document.documentElement.clientHeight - 120,
			tableData: [],
			sdate: "",
			pickerOptions: {
			            disabledDate(time) {
			                return time.getFullYear() != vm.currentYear;
			            }
			        },
			topicTotalData: [{
					formId: "",
					row: "",
					user: "袁汉龙",
					date: "2016-06-03",
					topic: "qrqrg",
					actionPlan: "qq",
					month: "1",
					week: "3",
					status: "Done"
				},
				{
					row: "",
					user: "李甲乙",
					date: "2015-06-03",
					topic: "qrqrg",
					actionPlan: "qq",
					month: "2",
					week: "4",
					status: "Done"
				}
			],
			currentYear: 2021,
			currentWeek:0,
			myTopicData: [{
					formId: "",
					row: "",
					user: "袁汉龙",
					date: "2016-06-03",
					topic: "qrqrg",
					actionPlan: "qq",
					month: "1",
					week: "3",
					status: "Done"
				},
				{
					row: "",
					user: "李甲乙",
					date: "2015-06-03",
					topic: "qrqrg",
					actionPlan: "qq",
					month: "2",
					week: "4",
					status: "Done"
				},
			],
			userList: [{
				row: "",
				user: "袁汉龙",
				email: "hanlong.yuan@valeo.com",
				dept: "IT",
				ps: "Y",
				n1: "关勇",
				n1Email: "yong.guan@valeo.com",
				key: "Y"

			}, {
				row: "",
				user: "李晃忆",
				email: "jiayi.li@valeo.com",
				dept: "HR",
				ps: "Y",
				n1: "关勇",
				n1Email: "yong.guan@valeo.com",
				key: "N"

			}],
			myTopicNav: false,
			deptMgrNav: false,
			content: "2-1",
			te: -1,
			tes: {
				hase: false,
				row: "",
				date: "",
				topic: "",
				actionPlan: "",
				status: "",
				month: "",
				week: "",
			},
			drawer: false,
			drawer1: false, // 显示月或者周结果
			rules: {
				date: [{
						required: true,
						message: 'Please enter date',
						trigger: 'change'
					},
					// { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
				],
				topic: [{
					required: true,
					message: 'Please enter topic',
					trigger: 'blur'
				}],
				actionPlan: [{
					required: false,
					message: 'Please enter action plan',
					trigger: 'blur'
				}],
				// week: [
				// 	{
				// 		message: 'Please enter week',
				// 		trigger: 'change',
				// 	},
				// 	{
				// 		min: 0,
				// 		max: 52,
				// 		message: '长度在 3 到 5 个字符',
				// 		trigger: 'blur'
				// 	}

				// ],
				status: [{
					required: true,
					message: 'Please enter status',
					trigger: 'change'
				}]

			}
		}
	},
	methods: {
		openView1(scope) {
			let row = scope.row,
				index = scope.$index;
			this.drawer1 = true;
		},
		handleOpen(key, keyPath) {
			console.log(key, keyPath);
		},
		handleClose1(key, keyPath) {
			console.log(key, keyPath);
		},
		handleSelect(key, keyPath) {
			console.log(key, keyPath)
			this.content = key;
			if (key == "2-1") {
				this.te = -1
			}
		},
		
		switchCollapse(key) {
   console.log(1)
		},
		expandRow(rows,e){
			console.log(rows)
			console.log(e)
			
		},
		topicNew() {
			this.te = -1;
			this.drawer = true;
			let tes = this.tes;
			tes.date = new Date();
			tes.topic = null;
			tes.actionPlan = null;
			tes.status = "Completed";
			tes.week = null;
			tes.month = null;
		},
		topicEdit(scope) {
			this.$refs.tes ? this.$refs.tes.resetFields() : null;
			let row = scope.row;
			let tes = this.tes
			tes.date = row.date;
			tes.topic = row.topic;
			tes.actionPlan = row.actionPlan;
			tes.status = row.status;
			this.te = scope.$index;
			this.drawer = true;
		},
		topicSubmit(e) {
			let tes = this[e];
			let index = this.te;
			let a = this.myTopicData[index];
			if (!tes.date || !tes.status || !tes.topic || tes.week > 53 || tes.week < 0) {
				return false;
			}
			if (index > -1) { // 修改
				if (a.date != tes.date ||
					a.topic != tes.topic ||
					a.actionPlan != tes.actionPlan ||
					a.status != tes.status

				) { //与之前比较有变化 

					a.date = tes.date
					a.topic = tes.topic
					a.actionPlan = tes.actionPlan
					a.status = tes.status
					a.week = tes.week
					a.month = tes.month
					// gsrun.editMyTop(a){


					// }
				} else { //与之前比较无变化
					console.log(2)
				}
			} else { // 新增
				this.myTopicData.push({
					user: "袁汉龙",
					date: tes.date,
					topic: tes.topic,
					actionPlan: tes.actionPlan,
					status: tes.status,
					week: tes.week,
					month: tes.month,

				})

			}
			console.log(this.te)
			this.te = -1;
			this.drawer = false;
		},
		handleClose(done) {
			this.$confirm('确认关闭？')
				.then(_ => {
					this.te = -1;
					done();
				})
				.catch(_ => {});
		},
		getWeek(dt) {
			let d1 = new Date(dt);
			let d2 = this.sdate;
			let rq = d1 - d2;
			let days = Math.ceil(rq / (24 * 60 * 60 * 1000));
			let num = Math.ceil(days / 7);
			return num;
		},
		drawerClose() {
			this.$confirm('确认关闭？')
				.then(_ => {
					this.te = -1;
					this.drawer = false
				})
				.catch(_ => {});


		},
		topicDelete(e) {

			this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.myTopicData.splice(e.$index, 1)
				this.$message({
					type: 'success',
					message: '删除成功!'
				});
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});
			});


		},
		openView1(scope) {
			let row = scope.row,
				index = scope.$index;
			this.drawer1 = true;
			
		},
		colseView1(done) {
			done();
		}
	},
	watch: {
		'tes.date'(val, oldVal) {
			if (val != oldVal && this.drawer) {
				let date = new Date(val)
				this.tes.week = this.getWeek(date);
				this.tes.month = date.getMonth() + 1;
			}
		}


	},
	// computed: {
	// 	tableHeight: function() {
	// 		console.log(70)
	// 		this.height = document.documentElement.clientHeight - 70;
	// 	},
	// 	getA: function() {
	// 		this.myTopicData[0][1] = "fk";
	// 		return 1
	// 	},

	// },

	mounted() {
		window.onresize = _ => {
			this.height = document.documentElement.clientHeight - 120
		};
	}
})
vm.myTopicNav = true;
vm.deptMgrNav = true;
vm.isCollapse = true;
const currentYear = new Date().getFullYear();
vm.currentYear = currentYear;
const cdate = new Date(currentYear, 0, 1)
const cweek = cdate.getDay()
if (cweek > 4) {
	vm.sdate = new Date(currentYear, 0, (8 - cweek))
} else {
	vm.sdate = new Date(currentYear, 0, (cweek - 7))

}
